package routes

import (
	"github.com/gin-gonic/gin"
	"usercenter/internal/handler"
	"usercenter/middleware"
	"usercenter/utils/resx"
)

func InitRouter(ginRouter *gin.Engine) {
	// 用户
	usercenterV1 := ginRouter.Group("/usercenter/v1")
	{
		// 鉴权通道
		usercenterV1.GET("/auth/:level", handler.Auth)

		// 公开组
		usercenterV1Nil := usercenterV1.Group("/nil")
		{
			// 测试
			usercenterV1Nil.GET("/ping", func(context *gin.Context) {
				context.JSON(200, resx.GinResp(resx.Success, "pong"))
			})
			usercenterV1Nil.POST("/login-pwd", handler.LoginByPwd)
			usercenterV1Nil.POST("/login-captcha", middleware.CaptchaMiddleware(), handler.LoginByCaptcha)
			usercenterV1Nil.POST("/register", middleware.CaptchaMiddleware(), handler.Register)
			usercenterV1Nil.POST("/forget", middleware.CaptchaMiddleware(), handler.ForgetPwd)

			usercenterV1Nil.Static("/image", "./static/image")
		}

		// 鉴权组
		usercenterV1Def := usercenterV1.Group("/def")
		{
			usercenterV1Def.GET("/info", handler.Info)
			usercenterV1Def.POST("/edit", handler.Edit)
			usercenterV1Def.POST("/edit-pwd", middleware.CaptchaMiddleware(), handler.EditPwd)
			usercenterV1Def.POST("/logout", handler.Logout)
			usercenterV1Def.POST("/unregister", middleware.CaptchaMiddleware(), handler.Unregister)
			usercenterV1Def.PUT("/upload", handler.Upload)
		}

		// 系统组（不对外公开，内网访问）
		sysCenterV1 := usercenterV1.Group("/sys")
		{
			sysCenterV1Nil := sysCenterV1.Group("/nil")
			{
				sysCenterV1Nil.POST("/login", handler.SysLogin)
			}
			sysCenterV1Def := sysCenterV1.Group("/def")
			{
				sysCenterV1Def.GET("/logout", handler.SysLogout)
			}
		}
	}
}
